package com.example.sportmeet

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    private lateinit var etUsername: EditText
    private lateinit var etPassword: EditText
    private lateinit var btnLogin: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // 初始化视图
        etUsername = findViewById(R.id.etUsername)
        etPassword = findViewById(R.id.etPassword)
        btnLogin = findViewById(R.id.btnLogin)

        // 设置登录按钮点击事件
        btnLogin.setOnClickListener {
            val username = etUsername.text.toString().trim()
            val password = etPassword.text.toString().trim()

            // 验证输入
            if (username.isEmpty()) {
                showToast("请输入用户名")
                return@setOnClickListener
            }

            if (password.isEmpty()) {
                showToast("请输入密码")
                return@setOnClickListener
            }

            // 验证凭据
            if (username != "admin" || password != "123") {
                showToast("用户名或密码错误")
                return@setOnClickListener
            }

            // 登录成功
            showToast("登录成功")
            startActivity(Intent(this, EntryActivity::class.java))
            finish()
        }
    }

    private fun showToast(message: String) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
    }
}